|
1
|
|
|
/* global window */ |
|
2
|
|
|
import React from 'react'; |
|
3
|
|
|
import PropTypes from 'prop-types'; |
|
4
|
|
|
import { |
|
5
|
|
|
Form, |
|
6
|
|
|
FormGroup, |
|
7
|
|
|
ControlLabel, |
|
8
|
|
|
FormControl, |
|
9
|
|
|
Button, |
|
10
|
|
|
Col, |
|
11
|
|
|
Alert, |
|
12
|
|
|
} from 'react-bootstrap'; |
|
13
|
|
|
|
|
14
|
|
|
import Api from '../common/api'; |
|
15
|
|
|
|
|
16
|
|
|
export default class ChangePassword extends React.Component { |
|
17
|
|
|
constructor(props) { |
|
18
|
|
|
super(props); |
|
19
|
|
|
this.state = { |
|
20
|
|
|
password: '', |
|
21
|
|
|
password2: '', |
|
22
|
|
|
}; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
onSubmit(e) { |
|
26
|
|
|
e.preventDefault(); |
|
27
|
|
|
if (this.state.password !== this.state.password2) { |
|
28
|
|
|
this.setState({ errorMessage: '비밀번호가 서로 다릅니다. 다시 입력해 주세요.' }); |
|
29
|
|
|
} else { |
|
30
|
|
|
Api.changePassword({ password: this.state.password }) |
|
31
|
|
|
.then(() => { |
|
32
|
|
|
const search = /redirect=(.*)[&]?/.exec(window.location.search); |
|
33
|
|
|
this.setState({ errorMessage: null }); |
|
34
|
|
|
window.location.href = search ? search[1] : '/'; |
|
35
|
|
|
}) |
|
36
|
|
|
.catch((err) => { |
|
37
|
|
|
this.setState({ errorMessage: (err && err.response && err.response.data) ? err.response.data.message : null }); |
|
38
|
|
|
}); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
render() { |
|
43
|
|
|
return ( |
|
44
|
|
|
<Col xs={6} xsOffset={3} md={4} mdOffset={4}> |
|
45
|
|
|
<Alert style={{ display: this.state.errorMessage ? 'block' : 'none' }} bsStyle="danger">{this.state.errorMessage}</Alert> |
|
46
|
|
|
<Alert bsStyle="info">임시 비밀번호를 사용하고 있는 계정입니다. 계속 하시려면 새로운 비밀번호를 입력하셔야 합니다.</Alert> |
|
47
|
|
|
<Form onSubmit={e => this.onSubmit(e)}> |
|
48
|
|
|
<FormGroup controlId="password"> |
|
49
|
|
|
<ControlLabel>새로운 패스워드</ControlLabel> |
|
50
|
|
|
<FormControl |
|
51
|
|
|
type="password" |
|
52
|
|
|
name="password" |
|
53
|
|
|
value={this.state.password} |
|
54
|
|
|
onChange={e => this.setState({ password: e.target.value })} placeholder="패스워드를 입력하세요" |
|
55
|
|
|
/> |
|
56
|
|
|
</FormGroup> |
|
57
|
|
|
<FormGroup controlId="password2"> |
|
58
|
|
|
<ControlLabel>새로운 패스워드 확인</ControlLabel> |
|
59
|
|
|
<FormControl |
|
60
|
|
|
type="password" |
|
61
|
|
|
name="password2" |
|
62
|
|
|
value={this.state.password2} |
|
63
|
|
|
onChange={e => this.setState({ password2: e.target.value })} placeholder="동일한 패스워드를 입력하세요" |
|
64
|
|
|
/> |
|
65
|
|
|
</FormGroup> |
|
66
|
|
|
<FormGroup> |
|
67
|
|
|
<Button type="submit">Submit</Button> |
|
68
|
|
|
</FormGroup> |
|
69
|
|
|
</Form> |
|
70
|
|
|
</Col> |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
ChangePassword.defaultProps = { |
|
76
|
|
|
errorMessage: '', |
|
77
|
|
|
}; |
|
78
|
|
|
|
|
79
|
|
|
ChangePassword.propTypes = { |
|
80
|
|
|
errorMessage: PropTypes.string, |
|
81
|
|
|
}; |
|
82
|
|
|
|